import { SharedEntity } from 'src/api/shared/entities/shared.entity';
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { ResourceRoleEntity } from './resource.role.entity';

@Entity('resource')
export class ResourceEntity extends SharedEntity {
  @Column({
    type: 'varchar',
    length: 100,
    name: 'name',
    comment: '资源名称',
  })
  name: string;

  @Column({
    type: 'varchar',
    name: 'type',
    comment: '类型',
  })
  type: string;

  @Column({
    type: 'boolean',
    default: false,
    name: 'is_show',
    comment: '菜单是否显示',
  })
  isShow: boolean;

  @Column({
    type: 'varchar',
    length: 30,
    nullable: true,
    name: 'icon',
    comment: '菜单图标',
  })
  icon: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    name: 'code',
    comment: '资源code',
  })
  code: string;

  @Column({
    type: 'int',
    nullable: true,
    name: 'sort',
    comment: '菜单排序',
  })
  sort: number;

  @Column({
    type: 'varchar',
    name: 'component_path',
    comment: '组件路径',
  })
  componentPath: string;

  @Column({
    type: 'varchar',
    name: 'component_name',
    comment: '组件名称',
  })
  componentName: string;

  @Column({
    type: 'boolean',
    default: false,
    name: 'cache',
    comment: '是否需要缓存',
  })
  cache: boolean;

  @Column({
    type: 'char',
    length: 36,
    nullable: true,
    name: 'parent_id',
    comment: '上一级id',
  })
  parentId: string;

  // 对应的资源
  @OneToMany(() => ResourceRoleEntity, (resourceRole) => resourceRole.resource)
  roleResource: ResourceRoleEntity[];
}
